package com.zjitc.config;

import javax.sql.DataSource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/3/12 13:46
 * @description:
 */
@Configuration
@Import(DataSourceConfiguration.class)
public class MyBatisXmlConfiguration
{
  @Bean
  public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource)
  {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    sqlSessionFactoryBean.setMapperLocations(new Resource[]{
        new FileSystemResource(
            "D:\\company_fire\\demo04-spring4\\target\\classes\\mapper\\UserMapper.xml")
    });
    return sqlSessionFactoryBean;
  }

  @Bean
  public MapperScannerConfigurer mapperScannerConfigurer()
  {
    MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
    mapperScannerConfigurer.setBasePackage("com.zjitc.mapper");
    mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");

    return mapperScannerConfigurer;
  }
}
